package com.wjc.myktapplication

import android.app.Application
import android.content.Context
import android.content.Intent
import com.idlefish.flutterboost.FlutterBoost
import com.idlefish.flutterboost.FlutterBoostDelegate
import com.idlefish.flutterboost.FlutterBoostRouteOptions
import com.idlefish.flutterboost.containers.FlutterBoostActivity
import com.wjc.myktapplication.data.NetworkManager
import io.flutter.embedding.android.FlutterActivityLaunchConfigs
import io.flutter.embedding.engine.FlutterEngine


/**
 * ClassName: com.wjc.myktapplication
 * Description:
 * JcChen on 2021.04.16.17:38
 */
class MyApplication : Application() {
    companion object {
        private lateinit var mApplication: MyApplication

        fun getContext(): Context {
            return mApplication
        }
    }

    override fun onCreate() {
        super.onCreate()
        mApplication = this
        NetworkManager.init(this, BuildConfig.DEL_EVN)
        FlutterBoost.instance().setup(this, object : FlutterBoostDelegate {
            override fun pushNativeRoute(options: FlutterBoostRouteOptions) {
                //这里根据options.pageName来判断你想跳转哪个页面，这里简单给一个
                val intent = Intent(FlutterBoost.instance().currentActivity(), MainActivity::class.java)
                FlutterBoost.instance().currentActivity().startActivityForResult(intent, options.requestCode())
            }

            override fun pushFlutterRoute(options: FlutterBoostRouteOptions) {
                val intent = FlutterBoostActivity.CachedEngineIntentBuilder(FlutterBoostActivity::class.java)
                    .backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.transparent)
                    .destroyEngineWithActivity(false)
                    .uniqueId(options.uniqueId())
                    .url(options.pageName())
                    .urlParams(options.arguments())
                    .build(FlutterBoost.instance().currentActivity())
                FlutterBoost.instance().currentActivity().startActivity(intent)
            }
        }) { engine: FlutterEngine? -> }
    }
}